package com.keshe.order.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keshe.order.entity.UserEntity;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.keshe.order.entity.OrderEntity;

import com.keshe.order.service.OrderService;
import com.keshe.common.utils.PageUtils;
import com.keshe.common.utils.R;



/**
 *
 *
 * @author tianfanfan
 * @email 2712855098@qq.com
 * @date 2023-01-02 14:28:26
 */
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 列表: 获取列表，包括订单和用户
     */
    @RequestMapping("/list")
    //@RequiresPermissions("order:order:list")
    public R list(@RequestParam Map<String, Object> params) {
        IPage<OrderEntity> pageInfo = orderService.getOrderList(params);
        return R.ok().put("page", pageInfo);
    }

    /*
    * @RequestMapping("/list-search")
     */
    //@RequiresPermissions("order:order:list")
    public R searchList(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.SearchQueryPage(params);
        return R.ok().put("page", page);
    }


    @RequestMapping("/info/{orderId}")
    //@RequiresPermissions("order:order:info")
    public R info(@PathVariable("orderId") Integer orderId){
        OrderEntity order = orderService.getOrderDatails(orderId);
        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:order:save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:order:update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);
        System.out.println(order);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:order:delete")
    public R delete(@RequestBody Integer[] orderIds){
		orderService.removeByIds(Arrays.asList(orderIds));

        return R.ok();
    }

}
